#!/bin/bash

interface=$1
output=$2

if [[ -z "$interface" ]]; then
    read -p "Interface: " interface
fi

if [[ -z "$output" ]]; then
    read -p "Output file: " output
fi

if [ -f "$output" ]; then
    > "$output"
fi

while true; do
    current_time=$(date +"%Y-%m-%d %H:%M:%S.%9N")
    tx_bytes=$(cat /sys/class/net/"$interface"/statistics/tx_bytes)
    rx_bytes=$(cat /sys/class/net/"$interface"/statistics/rx_bytes)
    echo "$current_time: $tx_bytes $rx_bytes" >> "$output"
done